package com.cloudcross.ssp.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.common.utils.SqlHelper;
import com.cloudcross.ssp.model.AdvAgent;
import com.cloudcross.ssp.service.IAdvAgentService;
import com.cloudcross.ssp.web.widget.SelectorController.ISelector;
import com.cloudcross.ssp.web.widget.SelectorController.ISelectorProvider;

@Service
public class AdvAgentService implements IAdvAgentService, ISelectorProvider {

	@Autowired
	protected GenericIBatisDao myBatisDao;
	
	@Override
	public AdvAgent findById(Long id) {
		return myBatisDao.get("advAgentSqlMapper.findById",id);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("value", searchValue);
		return myBatisDao.get("advAgentSqlMapper.countByParams",paramMap);
	}

	@Override
	public List<AdvAgent> findByParams(Map<String, Object> paramMap, Pager pager) {
		paramMap.put("pager", pager);
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("value", searchValue);
		return myBatisDao.get("advAgentSqlMapper.findByParams",paramMap);
	}

	@Override
	public boolean add(AdvAgent t) {
		 myBatisDao.save("advAgentSqlMapper.addAdvAgent", t);
		 return true;
	}

	@Override
	public boolean edit(AdvAgent t) {
		 myBatisDao.save("advAgentSqlMapper.editAdvAgent", t);
		 return true;
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		myBatisDao.save("advAgentSqlMapper.updateAdvAgentStatus",
				MapBuilder.create(HashMap.class)
					.add("advAgentIdList", idList)
					.add("modifyDate", new Date())
					.add("status", status).map());
		return true;
	}

	@Override
	public AdvAgent getNew(AdvAgent t) {
		return myBatisDao.get("advAgentSqlMapper.getNew", t);
	}

	@Override
	public List<AdvAgent> findAll() {
		return myBatisDao.getList("advAgentSqlMapper.findAll");
	}

	@Override
	public Map<String, List<? extends ISelector>> provideData(String[] parentId) {
		// TODO Auto-generated method stub
				List<AdvAgent> advAgentsList = findAll();
				return MapBuilder.create(HashMap.class).add("advAgentsList", advAgentsList)
						.map();
	}

	@Override
	public Long getId(Long operatorId) {
		return myBatisDao.get("advAgentSqlMapper.getId", operatorId);
	
	}

}
